package cn.ycxy.lbl.pojo.member.domain;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


@ApiModel("用户表")
@Data
@TableName("lbl_cs_user")
public class User implements UserDetails {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private String username;
    private String password;
    private String nickname;
    private String avatar;
    private String phone;
    private String email;
    private String weixinOpenid;
    private String sessionKey;

    private String sno;
    private String college;
    private String specialty;
    private String step;
    private String approveImg;
    private Integer approveStatus;

    private Integer isEnable;
    private String lastLoginIp;
    private Integer loginCount;
    private LocalDateTime LastLoginTime;
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    @TableField(exist = false)
    private List<UserAutority> authorities;

    public User() {
        authorities =new ArrayList<>();
        UserAutority authority=new UserAutority();
        authority.setAuthority("ROLE_user");
        authorities.add(authority);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
